<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.8.17"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>QuEST: State initialisations</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="style.css" rel="stylesheet" type="text/css"/>
        <link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
        <script type="text/javascript" src="jquery.smartmenus.js"></script>
        <!-- SmartMenus jQuery Bootstrap Addon -->
        <script type="text/javascript" src="jquery.smartmenus.bootstrap.js"></script>
        <!-- SmartMenus jQuery plugin -->
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand"><img alt="Logo" src="logo.png"/></a>
                    <a class="navbar-brand"><b>QuEST</b> v3.2.0<br>The Quantum Exact Simulation Toolkit</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel " style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">State initialisations</div>  </div>
</div><!--header-->
<div class="contents">

<p>Functions for preparing quantum states.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga4534403b721977b669bff7bf4e37f0fb"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#ga4534403b721977b669bff7bf4e37f0fb">cloneQureg</a> (<a class="el" href="structQureg.html">Qureg</a> targetQureg, <a class="el" href="structQureg.html">Qureg</a> copyQureg)</td></tr>
<tr class="memdesc:ga4534403b721977b669bff7bf4e37f0fb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set targetQureg to be a clone of copyQureg.  <a href="group__init.html#ga4534403b721977b669bff7bf4e37f0fb">More...</a><br /></td></tr>
<tr class="separator:ga4534403b721977b669bff7bf4e37f0fb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gada7230491a50cd409f8b00f5ee1db953"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#gada7230491a50cd409f8b00f5ee1db953">initBlankState</a> (<a class="el" href="structQureg.html">Qureg</a> qureg)</td></tr>
<tr class="memdesc:gada7230491a50cd409f8b00f5ee1db953"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialises a qureg to have all-zero-amplitudes.  <a href="group__init.html#gada7230491a50cd409f8b00f5ee1db953">More...</a><br /></td></tr>
<tr class="separator:gada7230491a50cd409f8b00f5ee1db953"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0379e21efca0767a22607fc0e26a5a22"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#ga0379e21efca0767a22607fc0e26a5a22">initClassicalState</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, long long int stateInd)</td></tr>
<tr class="memdesc:ga0379e21efca0767a22607fc0e26a5a22"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits to the classical state (also known as a "computational basis state") with index <code>stateInd</code>.  <a href="group__init.html#ga0379e21efca0767a22607fc0e26a5a22">More...</a><br /></td></tr>
<tr class="separator:ga0379e21efca0767a22607fc0e26a5a22"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga234bd34016f08288532791903b9884b5"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#ga234bd34016f08288532791903b9884b5">initPlusState</a> (<a class="el" href="structQureg.html">Qureg</a> qureg)</td></tr>
<tr class="memdesc:ga234bd34016f08288532791903b9884b5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits to the plus state <img class="formulaInl" alt="$ {| + \rangle}^{\otimes N} = \frac{1}{\sqrt{2^N}} (| 0 \rangle + | 1 \rangle)^{\otimes N} $" src="form_2.png"/> (and similarly <img class="formulaInl" alt="$ |+\rangle \langle+| $" src="form_3.png"/> for density matrices).  <a href="group__init.html#ga234bd34016f08288532791903b9884b5">More...</a><br /></td></tr>
<tr class="separator:ga234bd34016f08288532791903b9884b5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga9a348df3e1df623c3d4c4f12c3ee3fe8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#ga9a348df3e1df623c3d4c4f12c3ee3fe8">initPureState</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, <a class="el" href="structQureg.html">Qureg</a> pure)</td></tr>
<tr class="memdesc:ga9a348df3e1df623c3d4c4f12c3ee3fe8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits, which can be a state vector or density matrix, to a given pure state.  <a href="group__init.html#ga9a348df3e1df623c3d4c4f12c3ee3fe8">More...</a><br /></td></tr>
<tr class="separator:ga9a348df3e1df623c3d4c4f12c3ee3fe8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4589960486ec43dcd63bd985f1c4f398"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#ga4589960486ec43dcd63bd985f1c4f398">initStateFromAmps</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *reals, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *imags)</td></tr>
<tr class="memdesc:ga4589960486ec43dcd63bd985f1c4f398"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialise qureg by specifying the complete statevector.  <a href="group__init.html#ga4589960486ec43dcd63bd985f1c4f398">More...</a><br /></td></tr>
<tr class="separator:ga4589960486ec43dcd63bd985f1c4f398"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2f049055d4a51d0ea4d1a43b5234dedb"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#ga2f049055d4a51d0ea4d1a43b5234dedb">initZeroState</a> (<a class="el" href="structQureg.html">Qureg</a> qureg)</td></tr>
<tr class="memdesc:ga2f049055d4a51d0ea4d1a43b5234dedb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits to the classical zero state <img class="formulaInl" alt="$ {| 0 \rangle}^{\otimes N} $" src="form_1.png"/>.  <a href="group__init.html#ga2f049055d4a51d0ea4d1a43b5234dedb">More...</a><br /></td></tr>
<tr class="separator:ga2f049055d4a51d0ea4d1a43b5234dedb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gabc0c64f8adf307d2a44184dc0f8ca66e"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#gabc0c64f8adf307d2a44184dc0f8ca66e">setAmps</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, long long int startInd, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *reals, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *imags, long long int numAmps)</td></tr>
<tr class="memdesc:gabc0c64f8adf307d2a44184dc0f8ca66e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Overwrites a subset of the amplitudes in <code>qureg</code>, with those passed in <code>reals</code> and <code>imags</code>.  <a href="group__init.html#gabc0c64f8adf307d2a44184dc0f8ca66e">More...</a><br /></td></tr>
<tr class="separator:gabc0c64f8adf307d2a44184dc0f8ca66e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga5d0f3f71ea38d3c44597f8c2c2f014d4"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__init.html#ga5d0f3f71ea38d3c44597f8c2c2f014d4">setWeightedQureg</a> (<a class="el" href="structComplex.html">Complex</a> fac1, <a class="el" href="structQureg.html">Qureg</a> qureg1, <a class="el" href="structComplex.html">Complex</a> fac2, <a class="el" href="structQureg.html">Qureg</a> qureg2, <a class="el" href="structComplex.html">Complex</a> facOut, <a class="el" href="structQureg.html">Qureg</a> out)</td></tr>
<tr class="memdesc:ga5d0f3f71ea38d3c44597f8c2c2f014d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Modifies qureg <code>out</code> to the result of (<code>facOut</code> <code>out</code> + <code>fac1</code> <code>qureg1</code> + <code>fac2</code> <code>qureg2</code>), imposing no constraints on normalisation.  <a href="group__init.html#ga5d0f3f71ea38d3c44597f8c2c2f014d4">More...</a><br /></td></tr>
<tr class="separator:ga5d0f3f71ea38d3c44597f8c2c2f014d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Functions for preparing quantum states. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga4534403b721977b669bff7bf4e37f0fb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4534403b721977b669bff7bf4e37f0fb">&#9670;&nbsp;</a></span>cloneQureg()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cloneQureg </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>targetQureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>copyQureg</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Set targetQureg to be a clone of copyQureg. </p>
<p>Registers must either both be state-vectors, or both be density matrices. Only the quantum state is cloned, auxilary info (like recorded QASM) is unchanged. copyQureg is unaffected.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">targetQureg</td><td>the qureg to have its quantum state overwritten </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">copyQureg</td><td>the qureg to have its quantum state cloned in targetQureg. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00165">165</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;                                                    {</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a031812e1cf2c98d72d795cea7bbe73a5">validateMatchingQuregTypes</a>(targetQureg, copyQureg, __func__);</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(targetQureg, copyQureg, __func__);</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    </div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;    <a class="code" href="QuEST__internal_8h.html#aa4b77089145184d990848cd66993aa8b">statevec_cloneQureg</a>(targetQureg, copyQureg);</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu_8c_source.html#l01506">statevec_cloneQureg()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00495">validateMatchingQuregDims()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00499">validateMatchingQuregTypes()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__state__initialisations_8cpp_source.html#l00015">TEST_CASE()</a>.</p>

</div>
</div>
<a id="gada7230491a50cd409f8b00f5ee1db953"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gada7230491a50cd409f8b00f5ee1db953">&#9670;&nbsp;</a></span>initBlankState()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void initBlankState </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialises a qureg to have all-zero-amplitudes. </p>
<p>This is an unphysical state useful for iteratively building a state with e.g. <code>setWeightedQureg</code>, and should not be confused with the zero state |0...0&gt;</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>the object representing the set of all qubits to initialise </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00119">119</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;                                 {</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    <a class="code" href="QuEST__internal_8h.html#a758bad4237ff0bf3b4ff5be626a982ae">statevec_initBlankState</a>(qureg);</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    </div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a9a385fde708958617bbeb599064b8dcb">qasm_recordComment</a>(qureg, <span class="stringliteral">&quot;Here, the register was initialised to an unphysical all-zero-amplitudes &#39;state&#39;.&quot;</span>);</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__qasm_8c_source.html#l00120">qasm_recordComment()</a>, and <a class="el" href="QuEST__cpu_8c_source.html#l01398">statevec_initBlankState()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01072">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga0379e21efca0767a22607fc0e26a5a22"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0379e21efca0767a22607fc0e26a5a22">&#9670;&nbsp;</a></span>initClassicalState()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void initClassicalState </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>stateInd</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits to the classical state (also known as a "computational basis state") with index <code>stateInd</code>. </p>
<p>State-vectors will be initialised to <img class="formulaInl" alt="$ | \text{stateInd} \rangle $" src="form_8.png"/>, and density-matrices to <img class="formulaInl" alt="$ | \text{stateInd} \rangle \langle \text{stateInd} | $" src="form_9.png"/></p>
<p>Classical states are indexed from zero, so that <code>stateInd</code> = 0 produces <img class="formulaInl" alt="$ | 00 \dots 00 \rangle $" src="form_10.png"/>, and <code>stateInd</code> = 1 produces <img class="formulaInl" alt="$ | 00 \dots 01 \rangle $" src="form_11.png"/>, and <code>stateInd</code> = <img class="formulaInl" alt="$ 2^N - 1 $" src="form_12.png"/> produces <img class="formulaInl" alt="$ | 11 \dots 11 \rangle $" src="form_13.png"/>. Subsequent calls to getProbAmp will yield 0 for all indices except <code>stateInd</code>, and the phase of <code>stateInd's</code> amplitude will be 1 (real).</p>
<p>This function can be used to initialise a <code><a class="el" href="structQureg.html" title="Represents a system of qubits.">Qureg</a></code> in a specific binary state (e.g. <code>11001</code>) using a binary literal (supported by only some compilers): </p><pre class="fragment"> initClassicalState(qureg, 0b11001);
</pre><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>the object representing the set of qubits to be initialised </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">stateInd</td><td>the index (0 to the number of amplitudes, exclusive) of the state to give probability 1 </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">invalidQuESTInputError</td><td>if <code>stateInd</code> is outside [0, 2^N-1]. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00134">134</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;                                                             {</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a57dc69bb7a2217aafca676b0923d5e27">validateStateIndex</a>(qureg, stateInd, __func__);</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    </div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;        <a class="code" href="QuEST__internal_8h.html#a20a155f53efc45c16803d7539c2c199d">densmatr_initClassicalState</a>(qureg, stateInd);</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;        <a class="code" href="QuEST__internal_8h.html#a288dc4b46bdacd69cbf4a6fd070d26a7">statevec_initClassicalState</a>(qureg, stateInd);</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    </div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a55d0f243437a0bb3b7609a1090323aa3">qasm_recordInitClassical</a>(qureg, stateInd);</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu_8c_source.html#l01115">densmatr_initClassicalState()</a>, <a class="el" href="QuEST_8h_source.html#l00206">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__qasm_8c_source.html#l00458">qasm_recordInitClassical()</a>, <a class="el" href="QuEST__cpu_8c_source.html#l01470">statevec_initClassicalState()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00341">validateStateIndex()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__gates_8cpp_source.html#l00015">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga234bd34016f08288532791903b9884b5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga234bd34016f08288532791903b9884b5">&#9670;&nbsp;</a></span>initPlusState()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void initPlusState </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits to the plus state <img class="formulaInl" alt="$ {| + \rangle}^{\otimes N} = \frac{1}{\sqrt{2^N}} (| 0 \rangle + | 1 \rangle)^{\otimes N} $" src="form_2.png"/> (and similarly <img class="formulaInl" alt="$ |+\rangle \langle+| $" src="form_3.png"/> for density matrices). </p>
<p>This is the product state of <img class="formulaInl" alt="$N$" src="form_4.png"/> qubits where every classical state is uniformly populated (with real coefficient <img class="formulaInl" alt="$\frac{1}{\sqrt{2^N}}$" src="form_5.png"/> in the state-vector and <img class="formulaInl" alt="$\frac{1}{{2^N}}$" src="form_6.png"/> in the density-matrix). This is equivalent to applying a Hadamard to every qubit in the zero state: <img class="formulaInl" alt="$ \hat{H}^{\otimes N} {|0\rangle}^{\otimes N} $" src="form_7.png"/></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>the object representing the set of qubits to be initialised </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown (state-vector) </dd>
<dd>
Tyson Jones (density matrix, doc) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00125">125</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;                                {</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        <a class="code" href="QuEST__internal_8h.html#a2418bd9a6b9e6a0acf11faf5982d5d29">densmatr_initPlusState</a>(qureg);</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;        <a class="code" href="QuEST__internal_8h.html#a482fc361fd5f08075404c72e536316a0">statevec_initPlusState</a>(qureg);</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    </div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a627b0be7667c5a61a06b3b038fcc8b1b">qasm_recordInitPlus</a>(qureg);</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu_8c_source.html#l01154">densmatr_initPlusState()</a>, <a class="el" href="QuEST_8h_source.html#l00206">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__qasm_8c_source.html#l00430">qasm_recordInitPlus()</a>, and <a class="el" href="QuEST__cpu_8c_source.html#l01438">statevec_initPlusState()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__calculations_8cpp_source.html#l01072">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga9a348df3e1df623c3d4c4f12c3ee3fe8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga9a348df3e1df623c3d4c4f12c3ee3fe8">&#9670;&nbsp;</a></span>initPureState()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void initPureState </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>pure</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits, which can be a state vector or density matrix, to a given pure state. </p>
<p>If <code>qureg</code> is a state-vector, this merely makes <code>qureg</code> an identical copy of <code>pure</code>. If <code>qureg</code> is a density matrix, this makes <code>qureg</code> 100% likely to be in the <code>pure</code> state.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>the object representing the set of qubits to be initialised </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">pure</td><td>the pure state to be copied or to give probability 1 in qureg </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">invalidQuESTInputError</td><td>if <code>qureg</code> and <code>pure</code> have mismatching dimensions, or if <code>pure</code> is a density matrix. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00145">145</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;                                            {</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a7adc86571f1154558676d95daf0cbd1f">validateSecondQuregStateVec</a>(pure, __func__);</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(qureg, pure, __func__);</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160; </div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;        <a class="code" href="QuEST__internal_8h.html#ae5ad68d054875913d0f7ec654840a9ec">densmatr_initPureState</a>(qureg, pure);</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;        <a class="code" href="QuEST__internal_8h.html#aa4b77089145184d990848cd66993aa8b">statevec_cloneQureg</a>(qureg, pure);</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;    </div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a9a385fde708958617bbeb599064b8dcb">qasm_recordComment</a>(qureg, <span class="stringliteral">&quot;Here, the register was initialised to an undisclosed given pure state.&quot;</span>);</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l00452">densmatr_initPureState()</a>, <a class="el" href="QuEST_8h_source.html#l00206">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__qasm_8c_source.html#l00120">qasm_recordComment()</a>, <a class="el" href="QuEST__cpu_8c_source.html#l01506">statevec_cloneQureg()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00495">validateMatchingQuregDims()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00503">validateSecondQuregStateVec()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__state__initialisations_8cpp_source.html#l00211">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga4589960486ec43dcd63bd985f1c4f398"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4589960486ec43dcd63bd985f1c4f398">&#9670;&nbsp;</a></span>initStateFromAmps()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void initStateFromAmps </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *&#160;</td>
          <td class="paramname"><em>reals</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *&#160;</td>
          <td class="paramname"><em>imags</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialise qureg by specifying the complete statevector. </p>
<p>The real and imaginary components of the amplitudes are passed in separate arrays, each of which must have length <code>qureg.numAmpsTotal</code>. There is no automatic checking that the passed arrays are L2 normalised, so this can be used to prepare <code>qureg</code> in a non-physical state.</p>
<p>In distributed mode, this would require the complete statevector to fit in every node. To manually prepare a statevector which cannot fit in every node, use <a class="el" href="group__init.html#gabc0c64f8adf307d2a44184dc0f8ca66e" title="Overwrites a subset of the amplitudes in qureg, with those passed in reals and imags.">setAmps()</a></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>the object representing the set of qubits to be initialised </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">reals</td><td>array of the real components of the new amplitudes </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">imags</td><td>array of the imaginary components of the new amplitudes </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">invalidQuESTInputError</td><td>if <code>qureg</code> is not a statevector (i.e. is a density matrix) </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00157">157</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;                                                                {</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    </div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    <a class="code" href="QuEST__internal_8h.html#aa121d55f2ca09c06a96ddcd433c60b0f">statevec_setAmps</a>(qureg, 0, reals, imags, qureg.<a class="code" href="structQureg.html#adef4935cac95763c29164cf99b144ed4">numAmpsTotal</a>);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    </div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a9a385fde708958617bbeb599064b8dcb">qasm_recordComment</a>(qureg, <span class="stringliteral">&quot;Here, the register was initialised to an undisclosed given pure state.&quot;</span>);</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST_8h_source.html#l00215">Qureg::numAmpsTotal</a>, <a class="el" href="QuEST__qasm_8c_source.html#l00120">qasm_recordComment()</a>, <a class="el" href="QuEST__cpu_8c_source.html#l01237">statevec_setAmps()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00479">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__state__initialisations_8cpp_source.html#l00286">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga2f049055d4a51d0ea4d1a43b5234dedb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2f049055d4a51d0ea4d1a43b5234dedb">&#9670;&nbsp;</a></span>initZeroState()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void initZeroState </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialise a set of <img class="formulaInl" alt="$ N $" src="form_0.png"/> qubits to the classical zero state <img class="formulaInl" alt="$ {| 0 \rangle}^{\otimes N} $" src="form_1.png"/>. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>the object representing the set of all qubits to initialise </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown (state-vector) </dd>
<dd>
Tyson Jones (density matrix, doc) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00113">113</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;                                {</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    <a class="code" href="QuEST__internal_8h.html#a2ca0c6ba07ab2b4b437321bf17efc966">statevec_initZeroState</a>(qureg); <span class="comment">// valid for both statevec and density matrices</span></div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    </div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a4e21adca1f0ca03303bc2e57aaba4ce2">qasm_recordInitZero</a>(qureg);</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__qasm_8c_source.html#l00415">qasm_recordInitZero()</a>, and <a class="el" href="QuEST__cpu_8c_source.html#l01428">statevec_initZeroState()</a>.</p>

<p class="reference">Referenced by <a class="el" href="QuEST_8c_source.html#l00050">createDensityQureg()</a>, <a class="el" href="QuEST_8c_source.html#l00036">createQureg()</a>, and <a class="el" href="test__calculations_8cpp_source.html#l01000">TEST_CASE()</a>.</p>

</div>
</div>
<a id="gabc0c64f8adf307d2a44184dc0f8ca66e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gabc0c64f8adf307d2a44184dc0f8ca66e">&#9670;&nbsp;</a></span>setAmps()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void setAmps </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>startInd</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *&#160;</td>
          <td class="paramname"><em>reals</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *&#160;</td>
          <td class="paramname"><em>imags</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">long long int&#160;</td>
          <td class="paramname"><em>numAmps</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Overwrites a subset of the amplitudes in <code>qureg</code>, with those passed in <code>reals</code> and <code>imags</code>. </p>
<p>Only amplitudes with indices in [<code>startInd</code>, <code>startInd</code> + <code>numAmps</code>] will be changed, which means the new state may not be L2 normalised. This allows the user to initialise a custom state by setting batches of amplitudes.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>the statevector to modify </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">startInd</td><td>the index of the first amplitude in <code>qureg's</code> statevector to modify </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">reals</td><td>array of the real components of the new amplitudes </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">imags</td><td>array of the imaginary components of the new amplitudes </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">numAmps</td><td>the length of each of the reals and imags arrays. </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">invalidQuESTInputError</td><td>if <code>qureg</code> is not a statevector (i.e. is a density matrix), or if <code>startInd</code> is outside [0, <code>qureg.numAmpsTotal</code>], or if <code>numAmps</code> is outside [0, <code>qureg.numAmpsTotal</code>], or if <code>numAmps</code> + <code>startInd</code> is &gt;= qureg.numAmpsTotal. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00781">781</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00781"></a><span class="lineno">  781</span>&#160;                                                                                                     {</div>
<div class="line"><a name="l00782"></a><span class="lineno">  782</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a>(qureg, __func__);</div>
<div class="line"><a name="l00783"></a><span class="lineno">  783</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a6904359f35d0b61b2c8fcecfac836033">validateNumAmps</a>(qureg, startInd, numAmps, __func__);</div>
<div class="line"><a name="l00784"></a><span class="lineno">  784</span>&#160;    </div>
<div class="line"><a name="l00785"></a><span class="lineno">  785</span>&#160;    <a class="code" href="QuEST__internal_8h.html#aa121d55f2ca09c06a96ddcd433c60b0f">statevec_setAmps</a>(qureg, startInd, reals, imags, numAmps);</div>
<div class="line"><a name="l00786"></a><span class="lineno">  786</span>&#160;    </div>
<div class="line"><a name="l00787"></a><span class="lineno">  787</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a9a385fde708958617bbeb599064b8dcb">qasm_recordComment</a>(qureg, <span class="stringliteral">&quot;Here, some amplitudes in the statevector were manually edited.&quot;</span>);</div>
<div class="line"><a name="l00788"></a><span class="lineno">  788</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__qasm_8c_source.html#l00120">qasm_recordComment()</a>, <a class="el" href="QuEST__cpu_8c_source.html#l01237">statevec_setAmps()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00351">validateNumAmps()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00479">validateStateVecQureg()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__state__initialisations_8cpp_source.html#l00368">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga5d0f3f71ea38d3c44597f8c2c2f014d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5d0f3f71ea38d3c44597f8c2c2f014d4">&#9670;&nbsp;</a></span>setWeightedQureg()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void setWeightedQureg </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structComplex.html">Complex</a>&#160;</td>
          <td class="paramname"><em>fac1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structComplex.html">Complex</a>&#160;</td>
          <td class="paramname"><em>fac2</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg2</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structComplex.html">Complex</a>&#160;</td>
          <td class="paramname"><em>facOut</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>out</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Modifies qureg <code>out</code> to the result of (<code>facOut</code> <code>out</code> + <code>fac1</code> <code>qureg1</code> + <code>fac2</code> <code>qureg2</code>), imposing no constraints on normalisation. </p>
<p>Works for both statevectors and density matrices. Note that afterward, <code>out</code> may not longer be normalised and ergo no longer a valid statevector or density matrix. Users must therefore be careful passing <code>out</code> to other QuEST functions which assume normalisation in order to function correctly.</p>
<p><code>qureg1</code>, <code>qureg2</code> and <code>out</code> must be all state-vectors, or all density matrices, of equal dimensions. <code>out</code> can be one (or both) of <code>qureg1</code> and <code>qureg2</code>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">fac1</td><td>the complex number by which to scale <code>qureg1</code> in the output state </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg1</td><td>the first qureg to add to <code>out</code>, which is itself unmodified </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">fac2</td><td>the complex number by which to scale <code>qureg2</code> in the output state </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">qureg2</td><td>the second qureg to add to <code>out</code>, which is itself unmodified </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">facOut</td><td>the complex factor by which to multiply the current elements of <code>out</code>. <code>out</code> is completely overwritten if <code>facOut</code> is set to (<a class="el" href="structComplex.html" title="Represents one complex number.">Complex</a>) {.real=0,.imag=0} </td></tr>
    <tr><td class="paramdir">[in,out]</td><td class="paramname">out</td><td>the qureg to be modified, to be scaled by <code>facOut</code> then have <code>fac1</code> <code>qureg1</code> and <code>fac2</code> <code>qureg2</code> added to it. </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">invalidQuESTInputError</td><td>if <code>qureg1</code>, <code>qureg2</code> and <code>aren't</code> all state-vectors or all density matrices, or if the dimensions of <code>qureg1</code>, <code>qureg2</code> and <code>aren't</code> equal </td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Tyson Jones </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00797">797</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00797"></a><span class="lineno">  797</span>&#160;                                                                                                         {</div>
<div class="line"><a name="l00798"></a><span class="lineno">  798</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a031812e1cf2c98d72d795cea7bbe73a5">validateMatchingQuregTypes</a>(qureg1, qureg2, __func__);</div>
<div class="line"><a name="l00799"></a><span class="lineno">  799</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a031812e1cf2c98d72d795cea7bbe73a5">validateMatchingQuregTypes</a>(qureg1, out, __func__);</div>
<div class="line"><a name="l00800"></a><span class="lineno">  800</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(qureg1, qureg2,  __func__);</div>
<div class="line"><a name="l00801"></a><span class="lineno">  801</span>&#160;    <a class="code" href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a>(qureg1, out, __func__);</div>
<div class="line"><a name="l00802"></a><span class="lineno">  802</span>&#160; </div>
<div class="line"><a name="l00803"></a><span class="lineno">  803</span>&#160;    <a class="code" href="QuEST__internal_8h.html#ad64a23933361fafc1b6b1787759c2663">statevec_setWeightedQureg</a>(fac1, qureg1, fac2, qureg2, facOut, out);</div>
<div class="line"><a name="l00804"></a><span class="lineno">  804</span>&#160; </div>
<div class="line"><a name="l00805"></a><span class="lineno">  805</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a9a385fde708958617bbeb599064b8dcb">qasm_recordComment</a>(out, <span class="stringliteral">&quot;Here, the register was modified to an undisclosed and possibly unphysical state (setWeightedQureg).&quot;</span>);</div>
<div class="line"><a name="l00806"></a><span class="lineno">  806</span>&#160;} </div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__qasm_8c_source.html#l00120">qasm_recordComment()</a>, <a class="el" href="QuEST__cpu_8c_source.html#l03619">statevec_setWeightedQureg()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00495">validateMatchingQuregDims()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00499">validateMatchingQuregTypes()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__state__initialisations_8cpp_source.html#l00438">TEST_CASE()</a>.</p>

</div>
</div>
</div><!-- contents -->
<div class="ttc" id="aQuEST__validation_8c_html_a57dc69bb7a2217aafca676b0923d5e27"><div class="ttname"><a href="QuEST__validation_8c.html#a57dc69bb7a2217aafca676b0923d5e27">validateStateIndex</a></div><div class="ttdeci">void validateStateIndex(Qureg qureg, long long int stateInd, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00341">QuEST_validation.c:341</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a2418bd9a6b9e6a0acf11faf5982d5d29"><div class="ttname"><a href="QuEST__internal_8h.html#a2418bd9a6b9e6a0acf11faf5982d5d29">densmatr_initPlusState</a></div><div class="ttdeci">void densmatr_initPlusState(Qureg targetQureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01154">QuEST_cpu.c:1154</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a72feec2aaa05f98aed7f3c3fee141251"><div class="ttname"><a href="QuEST__validation_8c.html#a72feec2aaa05f98aed7f3c3fee141251">validateStateVecQureg</a></div><div class="ttdeci">void validateStateVecQureg(Qureg qureg, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00479">QuEST_validation.c:479</a></div></div>
<div class="ttc" id="aQuEST__qasm_8c_html_a4e21adca1f0ca03303bc2e57aaba4ce2"><div class="ttname"><a href="QuEST__qasm_8c.html#a4e21adca1f0ca03303bc2e57aaba4ce2">qasm_recordInitZero</a></div><div class="ttdeci">void qasm_recordInitZero(Qureg qureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__qasm_8c_source.html#l00415">QuEST_qasm.c:415</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a6904359f35d0b61b2c8fcecfac836033"><div class="ttname"><a href="QuEST__validation_8c.html#a6904359f35d0b61b2c8fcecfac836033">validateNumAmps</a></div><div class="ttdeci">void validateNumAmps(Qureg qureg, long long int startInd, long long int numAmps, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00351">QuEST_validation.c:351</a></div></div>
<div class="ttc" id="aQuEST__qasm_8c_html_a627b0be7667c5a61a06b3b038fcc8b1b"><div class="ttname"><a href="QuEST__qasm_8c.html#a627b0be7667c5a61a06b3b038fcc8b1b">qasm_recordInitPlus</a></div><div class="ttdeci">void qasm_recordInitPlus(Qureg qureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__qasm_8c_source.html#l00430">QuEST_qasm.c:430</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a20a155f53efc45c16803d7539c2c199d"><div class="ttname"><a href="QuEST__internal_8h.html#a20a155f53efc45c16803d7539c2c199d">densmatr_initClassicalState</a></div><div class="ttdeci">void densmatr_initClassicalState(Qureg qureg, long long int stateInd)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01115">QuEST_cpu.c:1115</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a2ca0c6ba07ab2b4b437321bf17efc966"><div class="ttname"><a href="QuEST__internal_8h.html#a2ca0c6ba07ab2b4b437321bf17efc966">statevec_initZeroState</a></div><div class="ttdeci">void statevec_initZeroState(Qureg qureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01428">QuEST_cpu.c:1428</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a758bad4237ff0bf3b4ff5be626a982ae"><div class="ttname"><a href="QuEST__internal_8h.html#a758bad4237ff0bf3b4ff5be626a982ae">statevec_initBlankState</a></div><div class="ttdeci">void statevec_initBlankState(Qureg qureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01398">QuEST_cpu.c:1398</a></div></div>
<div class="ttc" id="aQuEST__qasm_8c_html_a55d0f243437a0bb3b7609a1090323aa3"><div class="ttname"><a href="QuEST__qasm_8c.html#a55d0f243437a0bb3b7609a1090323aa3">qasm_recordInitClassical</a></div><div class="ttdeci">void qasm_recordInitClassical(Qureg qureg, long long int stateInd)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__qasm_8c_source.html#l00458">QuEST_qasm.c:458</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_aa121d55f2ca09c06a96ddcd433c60b0f"><div class="ttname"><a href="QuEST__internal_8h.html#aa121d55f2ca09c06a96ddcd433c60b0f">statevec_setAmps</a></div><div class="ttdeci">void statevec_setAmps(Qureg qureg, long long int startInd, qreal *reals, qreal *imags, long long int numAmps)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01237">QuEST_cpu.c:1237</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_aa4b77089145184d990848cd66993aa8b"><div class="ttname"><a href="QuEST__internal_8h.html#aa4b77089145184d990848cd66993aa8b">statevec_cloneQureg</a></div><div class="ttdeci">void statevec_cloneQureg(Qureg targetQureg, Qureg copyQureg)</div><div class="ttdoc">works for both statevectors and density matrices</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01506">QuEST_cpu.c:1506</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a87d22240ccfd81827a2a34b8d569d347"><div class="ttname"><a href="QuEST__validation_8c.html#a87d22240ccfd81827a2a34b8d569d347">validateMatchingQuregDims</a></div><div class="ttdeci">void validateMatchingQuregDims(Qureg qureg1, Qureg qureg2, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00495">QuEST_validation.c:495</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a482fc361fd5f08075404c72e536316a0"><div class="ttname"><a href="QuEST__internal_8h.html#a482fc361fd5f08075404c72e536316a0">statevec_initPlusState</a></div><div class="ttdeci">void statevec_initPlusState(Qureg qureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01438">QuEST_cpu.c:1438</a></div></div>
<div class="ttc" id="aQuEST__qasm_8c_html_a9a385fde708958617bbeb599064b8dcb"><div class="ttname"><a href="QuEST__qasm_8c.html#a9a385fde708958617bbeb599064b8dcb">qasm_recordComment</a></div><div class="ttdeci">void qasm_recordComment(Qureg qureg, char *comment,...)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__qasm_8c_source.html#l00120">QuEST_qasm.c:120</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_ad64a23933361fafc1b6b1787759c2663"><div class="ttname"><a href="QuEST__internal_8h.html#ad64a23933361fafc1b6b1787759c2663">statevec_setWeightedQureg</a></div><div class="ttdeci">void statevec_setWeightedQureg(Complex fac1, Qureg qureg1, Complex fac2, Qureg qureg2, Complex facOut, Qureg out)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l03619">QuEST_cpu.c:3619</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a288dc4b46bdacd69cbf4a6fd070d26a7"><div class="ttname"><a href="QuEST__internal_8h.html#a288dc4b46bdacd69cbf4a6fd070d26a7">statevec_initClassicalState</a></div><div class="ttdeci">void statevec_initClassicalState(Qureg qureg, long long int stateInd)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l01470">QuEST_cpu.c:1470</a></div></div>
<div class="ttc" id="astructQureg_html_acf78445e9435d09f44f0cc832c6aee79"><div class="ttname"><a href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">Qureg::isDensityMatrix</a></div><div class="ttdeci">int isDensityMatrix</div><div class="ttdoc">Whether this instance is a density-state representation.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00206">QuEST.h:206</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a031812e1cf2c98d72d795cea7bbe73a5"><div class="ttname"><a href="QuEST__validation_8c.html#a031812e1cf2c98d72d795cea7bbe73a5">validateMatchingQuregTypes</a></div><div class="ttdeci">void validateMatchingQuregTypes(Qureg qureg1, Qureg qureg2, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00499">QuEST_validation.c:499</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_a7adc86571f1154558676d95daf0cbd1f"><div class="ttname"><a href="QuEST__validation_8c.html#a7adc86571f1154558676d95daf0cbd1f">validateSecondQuregStateVec</a></div><div class="ttdeci">void validateSecondQuregStateVec(Qureg qureg2, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00503">QuEST_validation.c:503</a></div></div>
<div class="ttc" id="astructQureg_html_adef4935cac95763c29164cf99b144ed4"><div class="ttname"><a href="structQureg.html#adef4935cac95763c29164cf99b144ed4">Qureg::numAmpsTotal</a></div><div class="ttdeci">long long int numAmpsTotal</div><div class="ttdoc">Total number of amplitudes, which are possibly distributed among machines.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00215">QuEST.h:215</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_ae5ad68d054875913d0f7ec654840a9ec"><div class="ttname"><a href="QuEST__internal_8h.html#ae5ad68d054875913d0f7ec654840a9ec">densmatr_initPureState</a></div><div class="ttdeci">void densmatr_initPureState(Qureg targetQureg, Qureg copyQureg)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l00452">QuEST_cpu_distributed.c:452</a></div></div>
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
</body>
        <script type="text/javascript" src="boot.js"></script>
</html>
